package jMenu;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.print.DocFlavor.URL;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
import javax.swing.border.EmptyBorder;

public class Menu extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Menu frame = new Menu();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Menu() {
		getContentPane().setLayout(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		// contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		// contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.setLayout(null);
		setContentPane(contentPane);

		// barra
		JMenuBar barraMenu = new JMenuBar();
		barraMenu.setBounds(0, 0, this.getWidth(), 20);
		// menu
		JMenu mClients = new JMenu("Clients");
		contentPane.add(barraMenu);
		// items del menu
		barraMenu.add(mClients);
		
		JMenuItem myNewItem = new JMenuItem("Nou");
		myNewItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println(myNewItem.getText());
			}
		});
		mClients.add(myNewItem);

		JMenuItem myActItem = new JMenuItem("Actualitzar");
		mClients.add(myActItem);

		JMenu mySearchMenu = new JMenu("Buscar");
		mClients.add(mySearchMenu);

		JMenuItem mySearchDBItem = new JMenuItem("A la base de dades");
		mySearchDBItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println(mySearchDBItem.getText());
			}
		});
		mySearchMenu.add(mySearchDBItem);

		JMenuItem mySearchHDItem = new JMenuItem("Al disc dur");
		mySearchHDItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println(mySearchHDItem.getText());
			}
		});
		mySearchMenu.add(mySearchHDItem);

		JSeparator sep = new JSeparator();
		mClients.add(sep);
		JMenuItem mydelItem = new JMenuItem("Borrar");
		mClients.add(mydelItem);

		JMenuItem myExitItem = new JMenuItem("Sortir");
		myExitItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		barraMenu.add(myExitItem);
		
		contentPane.add(barraMenu);
		JToolBar toolBar = new JToolBar();
		contentPane.add(toolBar, BorderLayout.SOUTH);
		URL url = getClass().getResource("casita.png");
		JButton b1 = new JButton(new ImageIcon(url));
		
	}

}
